# -*- encoding=utf8 -*-
__author__ = "chen"

import random

from common.common_util import *

def cangbaotu(idx):
    '''
    使用藏宝图，进行挖宝
    :param idx: 设备序列号
    :return: 无
    '''
    connect_device(f'Android:///{idx}')
    for i in range(100):
        print(f"执行次数：{i}")
        try:
            pcos = wait(Template(r"cangbaotu_home.png", record_pos=(0.358, 0.153), resolution=(1600, 900)), 300) # 连续两张挖图的最大间隔值，设为超时时间
            if pcos:
                app_touch(pcos, [-20, 20], [-1, 11])
        except:
            G.LOGGING.info(f"设备：{idx}，挖宝结束，共挖宝次数：{i}")
            filename = os.path.join(base_path, "cangbaotu", "sreenshot", f"{idx}-test_end.png")
            snapshot(filename=filename, msg=f"{idx} 任务结束")
            break

if __name__ == '__main__':
    # part1 获取有效设备
    device_list = adb_devices(devs)
    # part2 执行挖宝
    for i in range(len(device_list)):
        print(device_list[i])
        p = Process(target=cangbaotu,args=(device_list[i],))
        p.start()